package com.yupi.yuojbackendcommon.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author FengHuan Wang
 * @Date 2025/2/9 9:29
 * @Version 1.0
 */
@Configuration
@ConfigurationProperties(prefix = "spring.redisson")
@Data
public class RedissonConfig {

    /**
     * redis集群相关配置
     */
    private String host;
    private int port;
    private String password;



    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        // 构建节点地址
        String nodeAddress = "redis://" + host + ":" + port;

        SingleServerConfig singleServerConfig = config.useSingleServer()
                .setAddress(nodeAddress)
                .setPassword(password);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}